package com.ruoyi.biz.letter.controller;

import java.util.List;
import java.util.Objects;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.biz.letter.domain.BizMayorHotline;
import com.ruoyi.biz.letter.util.AcceptDeptUtil;
import com.ruoyi.biz.letter.util.CategoryUtil;
import com.ruoyi.common.utils.uuid.Seq;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.biz.letter.domain.BizMessageBoard;
import com.ruoyi.biz.letter.service.IBizMessageBoardService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 人民网留言板Controller
 *
 * @author Fei.Cong
 * @date 2024-07-18
 */
@RestController
@RequestMapping("/message/board")
public class BizMessageBoardController extends BaseController {

    @Autowired
    private IBizMessageBoardService bizMessageBoardService;

    /**
     * 查询人民网留言板列表
     */
    @PreAuthorize("@ss.hasPermi('message:board:list')")
    @GetMapping("/list")
    public AjaxResult list(BizMessageBoard bizMessageBoard) {
        LambdaQueryWrapper<BizMessageBoard> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        return success(bizMessageBoardService.list(lambdaQueryWrapper));
    }

    /**
     * 分页查询人民网留言板列表
     */
    @PreAuthorize("@ss.hasPermi('message:board:list')")
    @GetMapping("/page")
    public TableDataInfo page(BizMessageBoard bizMessageBoard) {
        CategoryUtil.handleQueryCategoryId(bizMessageBoard);
        AcceptDeptUtil.handleQueryAcceptDept(bizMessageBoard);
        return getDataTable(bizMessageBoardService.pageList(bizMessageBoard, startPage()));
    }

    /**
     * 导出人民网留言板列表
     */
    @PreAuthorize("@ss.hasPermi('message:board:export')")
    @Log(title = "人民网留言板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizMessageBoard bizMessageBoard) {
        List<BizMessageBoard> list = bizMessageBoardService.queryList(bizMessageBoard);
        ExcelUtil<BizMessageBoard> util = new ExcelUtil<BizMessageBoard>(BizMessageBoard.class);
        util.exportExcel(response, list, "人民网留言板数据");
    }

    /**
     * 获取人民网留言板详细信息
     */
    @PreAuthorize("@ss.hasPermi('message:board:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        BizMessageBoard bizMessageBoard = bizMessageBoardService.getById(id);
        CategoryUtil.getCategoryIds(bizMessageBoard);
        AcceptDeptUtil.getAcceptDept(bizMessageBoard);
        return success(bizMessageBoard);
    }

    /**
     * 新增人民网留言板
     */
    @PreAuthorize("@ss.hasPermi('message:board:add')")
    @Log(title = "人民网留言板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizMessageBoard bizMessageBoard) {
        bizMessageBoard.setLetterNumber(Seq.getId());
        CategoryUtil.buildCategoryId(bizMessageBoard);
        AcceptDeptUtil.buildAcceptDept(bizMessageBoard);
        return toAjax(bizMessageBoardService.save(bizMessageBoard));
    }

    /**
     * 修改人民网留言板
     */
    @PreAuthorize("@ss.hasPermi('message:board:edit')")
    @Log(title = "人民网留言板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizMessageBoard bizMessageBoard) {
        CategoryUtil.buildCategoryId(bizMessageBoard);
        AcceptDeptUtil.buildAcceptDept(bizMessageBoard);
        return toAjax(bizMessageBoardService.updateById(bizMessageBoard));
    }

    /**
     * 删除人民网留言板
     */
    @PreAuthorize("@ss.hasPermi('message:board:remove')")
    @Log(title = "人民网留言板", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids) {
        return toAjax(bizMessageBoardService.removeBatchByIds(ids));
    }
}
